package com.xyhuo.leetcode.november;

import java.util.ArrayList;
import java.util.List;

/**
 * 回文数
 * https://leetcode.cn/problems/palindrome-number/
 *
 * @time 2023/11/27
 */
public class IsPalindrome {

    public boolean isPalindrome(int x) {
        if (x < 0) {
            return false;
        }
        List<Integer> numList = new ArrayList<>();
        while (true) {
            if (x < 10) {
                numList.add(x);
                break;
            }
            numList.add(x % 10);
            x = x / 10;
        }
        int size = numList.size();
        int half = size / 2;
        for (int i = 0; i < half; i++) {
            if (numList.get(i) != numList.get(size - 1 - i)) {
                return false;
            }
        }
        return true;
    }
}
